<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jspf/must/basePath.jspf" %>
<!--后台UI组件Start-->
<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI.jspf" %>
<%@include file="/WEB-INF/jspf/zj/ztree/ztree.jspf" %>
<!--后台UI组件End-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script src="power/syspower/VIEW_SYSPOWER.js" type="text/javascript"></script>
        <script type="text/javascript">
//-------------------------------全局变量-------------------------------------------------
            var UPDATE;
            var GRID;
            var ADD;
            $(function() {
                powerTree("#SYSPOWERID", true);
                GRID = $("#divID_GRID").ligerGrid({
                    columns: [
                        {display: '账号', name: 'user_account', width: 120, align: 'left'}
                        , {display: '用户名', name: 'user_name', width: 120, align: 'left'}
                        , {display: '状态', name: 'style', width: 42, align: 'left', render: function(v) {
                                switch (v.style) {
//                                    case 0 :
//                                        return "新增";
                                    case 1 :
                                        return "禁用";
                                    case 2 :
                                        return "启用";
                                    default:
                                        return v.style;
                                }
                            }
                        }
                        , {display: '类型', name: 'sort', width: 59, align: 'left', render: function(v) {
                                switch (v.sort) {
//                                    case 0 :
//                                        return "超级管理员";
                                    case 1 :
                                        return "管理员";
                                    case 2 :
                                        return "普通成员";
                                    default:
                                        return v.sort;
                                }
                            }
                        }
                        , {display: '创建时间', name: 'cdate', width: 110, align: 'left'}
                        , {display: '上次登陆时间', name: 'ldate', width: 120, align: 'left'}
                    ]
                    , usePager: true
                    , url: 'weixinkeji/dev/power/user/sysuser/manager/sPage.imy'
                    , width: '650px'
                    , height: '97%'
                    , onSelectRow: user_click
                    , detail: {onShowDetail: f_showMyRole, height: 'auto', width: '600'}
                });
                function f_showMyRole(row, detailPanel, callback) {
                    var gridd = document.createElement('div');
                    $(detailPanel).append(gridd);
                    $(gridd).css('margin', 2).ligerGrid({
                        columns: [
                            {display: '角色', name: 'role_name', width: 190, align: 'left'}
                            , {display: '备注', name: 'role_info', width: 190, align: 'left'}
                            , {display: '创建时间', name: 'cdate', width: 120, align: 'center'}
                        ]
                        , url: 'weixinkeji/dev/power/center/sysur/manager/s/userRole1NLigerui.imy?uID=' + row.user_id
                        , showTitle: false
                        , width: '90%'
                        , onAfterShowData: callback
                        , frozen: false
                        , usePager: false
                    });
                }
                $("#toptoolbar").ligerToolBar({items: [
                        {text: '增加', click: add}
                        , {line: true}
                        , {text: '修改', click: update}
                        , {line: true}
                        , {text: '删除', click: dell}
                        , {line: true}
                        , {text: '继承角色', click: f_UserExtedsRole}
                        , {line: true}
                        , {text: '继承权限', click: f_UserExtedsPower}
                    ]});
            });
//-------------------------------GRID列函数-----------------------------------------------
            function user_click(rowdata, rID, rowobj) {
                zt_check("SYSPOWERID", false);
                var USER_POWER = myajax("weixinkeji/dev/power/center/sysup/manager/s/userRole1NLigerui.imy", {"uID": rowdata.user_id});
                for (var i = 0; i < USER_POWER.length; i++) {
                    setPowerTree("SYSPOWERID", USER_POWER[i].power_id);
                }
            }
            function reloadRole() {
                GRID.reload();
                zt_check("SYSPOWERID", false);
            }
//-------------------------------增删改操作-----------------------------------------------
            var EXTENDSROLE;
            var EXTENDSPOWER;
            function f_UserExtedsRole() {
                var row = GRID.getSelectedRow();
                if (null == row || null != EXTENDSROLE)
                    return;
                EXTENDSROLE = openURL_Event("继承角色", EXTENDSROLE, "power/sysrole/sysroleCheckbox_user.jsp?user_id=" + row.user_id, 520, 700, f_d);
                function f_d() {
                    EXTENDSROLE = null;
                    GRID.reload();
                }
            }
            function f_UserExtedsPower() {
                var row = GRID.getSelectedRow();
                if (null == row || null != EXTENDSPOWER)
                    return;
                EXTENDSPOWER = openURL_Event("继承权限", EXTENDSPOWER, "power/syspower/syspowerCheckbox_user.jsp?user_id=" + row.user_id, 520, 700, f_d);
                function f_d() {
                    EXTENDSPOWER = null;
                    GRID.reload();
                }
            }
            function add() {
                ADD = openURL_Event("用户管理添加", ADD, "power/sysuser/sysuser_A.jsp", 400, 900, f_d);
                function f_d() {
                    ADD = null;
                    GRID.reload();
                }
            }
            function update() {
                var row = GRID.getSelectedRow();
                if (!row) {
                    msg_tip("错误", "请选择行");
                    return;
                } else if (row.user_id.length > 10) {
                    UPDATE = openURL_Event("用户管理修改", UPDATE, "weixinkeji/dev/power/user/sysuser/adu/update.imy?id=" + row.user_id, 420, 700, f_d);
//                    UPDATE.max();
                }
                function f_d() {
                    UPDATE = null;
                    GRID.reload();
                }
            }
            function dell() {
                var rows = GRID.getSelectedRows();
                var ids = "";
                for (var i = 0; i < rows.length; i++) {
                    ids = ids + "," + rows[i].user_id;
                }
                ids = ids.substring(1);
                if (rows.length < 1) {
                    msg_tip("操作提示", "请选择行", 200, 50);
                    return;
                } else {
                    if (post_json("weixinkeji/dev/power/user/sysuser/adu/dell.imy", {"id": ids})) {
                        GRID.reload();
                    }
                }
            }
        </script>
    </head>
    <body>  
        <div id="toptoolbar"></div> 
        <div id="divID_GRID" style="margin:0; padding:0 ;float:left"></div>
        <div>
            <ul id="SYSPOWERID" class="ztree" style="height: 510px; overflow:auto;"></ul>
        </div>
    </body>
</html>
